package com.zy.config;

import com.zy.filter.WebCustomerFilter;
import com.zy.filter.WebCustomerFilter2;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author CarreyZhou
 * @Date: 2024/5/6 14:20
 * Servlet配置
 */
@Configuration
public class ServletConfig {

    @Bean
    public FilterRegistrationBean<WebCustomerFilter> webCustomerFilter() {
        FilterRegistrationBean<WebCustomerFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new WebCustomerFilter());
        // 配置需要过滤的请求
        filterRegistrationBean.addUrlPatterns("/login/test");
        // 设置filter的名称
        filterRegistrationBean.setName("webCustomerFilter");
        // 设置filter的顺序
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean<WebCustomerFilter2> webCustomerFilter2() {
        FilterRegistrationBean<WebCustomerFilter2> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new WebCustomerFilter2());
        // 配置需要过滤的请求
        filterRegistrationBean.addUrlPatterns("/*");
        // 设置filter的名称
        filterRegistrationBean.setName("webCustomerFilter2");
        // 设置filter的顺序
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }

}
